﻿using System;
using System.Globalization;

namespace RadaCode.SwissKnife
{
    public static class TimeSpanToReadableString
    {
        public static string Convert(TimeSpan data)
        {
            return Convert(data, new CultureInfo(""));
        }

        public static string Convert(TimeSpan data, CultureInfo culture)
        {
            if (data.Days >= 1)
                {
                    return String.Format(GetLocalizedDHM(culture), data.Days, data.Hours, data.Minutes);
                }
                else if(data.Hours >= 1)
                {
                    return String.Format(GetLocalizedHM(culture), data.Hours, data.Minutes);
                }
                else return String.Format(GetLocalizedM(culture), data.Minutes);
        }

        private static string GetLocalizedDHM(CultureInfo culture)
        {
            switch (culture.TwoLetterISOLanguageName)
            {
                case "ru":
                    return "{0} д. {1} ч. {2} мин.";
                default:
                    return "{0} d. {1} h. {2} min.";
            }
        }

        private static string GetLocalizedHM(CultureInfo culture)
        {
            switch (culture.TwoLetterISOLanguageName)
            {
                case "ru":
                    return "{0} ч. {1} мин.";
                default:
                    return "{0} h. {1} min.";
            }
        }

        private static string GetLocalizedM(CultureInfo culture)
        {
            switch (culture.TwoLetterISOLanguageName)
            {
                case "ru":
                    return "{0} мин.";
                default:
                    return "{0} min.";
            }
        }
    }
}
